import java.util.*;
public class OrderSys {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int num2=1;//num2=0返回主菜单栏
        String names[]=new String[5];//客户姓名
        String dishes[]=new String[5];//已点菜名
        int times[]=new int[5];//送餐时间
        String addresses[]=new String[5];//送餐地址
        int totalAmount[]=new int[5];//点菜总金额
        String  states[]=new String[5];//订单状态
        int count[] = new int[4];//点赞计数
        do {
            System.out.println("欢迎使用“吃货联盟订餐”");
            System.out.println("*******************************");
            System.out.println("1、我要订餐\n2、查看餐袋\n3、签收订单\n4、删除订单\n5、我要点赞\n6、退出系统");
            System.out.println("*******************************");
            System.out.print("请选择：");
            if (input.hasNextInt()) {
                int num = input.nextInt();//主菜单选择项
                switch (num) {
                    case 1:
                        for (int i = 0; i <5; i++) {
                            if(names[i]==null){
                            System.out.println("************我要订餐**************");
                            System.out.print("请输入姓名：");
                            names[i] = input.next();
                            System.out.println("\t\t\t序号\t\t名称\t\t单价\t\t点赞数");
                            System.out.println(" \t\t\t1\t\t红烧排骨\t30元\t\t"+count[0]);
                            System.out.println(" \t\t\t2\t\t季蔬\t\t10元\t\t"+count[1]);
                            System.out.println(" \t\t\t3\t\t肉末茄子\t15元\t\t"+count[2]);
                            System.out.println(" \t\t\t4\t\t红烧牛肉\t45元\t\t"+count[3]);
                            System.out.print("请选择菜品编号：");
                            int num3=input.nextInt();//菜品编号
                            double prices=0;
                            switch (num3){
                                case 1:
                                    dishes[i]="红烧排骨";
                                    prices=30;
                                    break;
                                case 2:
                                    dishes[i]="季菜";
                                    prices=10;
                                    break;
                                case 3:
                                    dishes[i]="肉末茄子";
                                    prices=15;
                                    break;
                                case 4:
                                    dishes[i]="红烧牛肉";
                                    prices=45;
                                    break;
                                default:
                                    System.out.println("菜品不存在！");
                                    break;
                            }
                            System.out.print("请选择份数：");
                            int num4=input.nextInt();//菜品份数
                            totalAmount[i]+=prices*num4;
                            double tip=6;//未满50元加送餐费6元
                            if (totalAmount[i]>=50){
                                tip=0;
                            }else{
                                totalAmount[i]+=tip;
                            }
                            dishes[i]=dishes[i]+num4;
                            boolean isinput=false;
                            System.out.print("请输入送餐时间（送餐时间是10点到20点之间整点送餐）：");
                            do{
                                times[i]=input.nextInt();
                                if (times[i]<=20&&times[i]>=10) {
                                    isinput=true;
                                }else{
                                    System.out.print("请重新输入：");
                                }
                            }while (!isinput);
                            System.out.print("请输入送餐地址：");
                            addresses[i]=input.next();
                            System.out.println("订餐成功！");
                            states[i]="已预订";
                            System.out.println("您的定是："+dishes[i]+"份"+"\n"+"送餐时间:"+times[i]+"点"+"\n"
                                    +"餐费："+(totalAmount[i]-tip)+"元"+"服务费："+tip+"元"+"总计："+totalAmount[i]+"元");
                            }else{
                                continue;
                            }
                            break;
                        }
                        System.out.print("输入0返回：");
                        num2 = input.nextInt();
                        break;
                    case 2:
                        System.out.println("************查看餐袋**************");
                        System.out.println("序号\t\t\t订餐人\t\t\t餐品信息\t\t\t\t送餐时间\t\t送餐地址\t\t\t\t\t\t" +
                                "总金额"+"\t\t"+"订单状态");
                        for (int i = 0; i <5; i++) {
                            if (names[i]!=null) {
                                System.out.println((i + 1) + "\t\t\t" + names[i] +"\t\t\t"+ dishes[i]+"份"+"\t\t\t" + times[i] + "\t\t\t" + addresses[i] + "\t\t\t" +
                                        +totalAmount[i] +"元"+ "\t\t" + states[i]);
                            }
                        }
                        System.out.print("输入0返回：");
                        num2 = input.nextInt();
                        break;
                    case 3:
                        System.out.println("************签收订单**************");
                        System.out.print("请确定要签收的序号：");
                        int num5=input.nextInt();//要签收的序号
                            if (states[num5-1].equals("已预订")){
                                System.out.println("订单签收成功！");
                                states[num5-1]="已完成";
                            }else{
                                System.out.println("订单已签收！");
                            }
                        System.out.print("输入0返回：");
                        num2 = input.nextInt();
                        break;
                    case 4:
                        System.out.println("************删除订单**************");
                        System.out.print("请输入要删除订单序号：");
                        int num6=input.nextInt();//num6要删除订单序号
                            if (states[num6-1].equals("已完成")==false){
                                System.out.println("未被签收，不能删除！");
                            }else{
                                for (int i = num6; i < 5; i++) {
                                    names[i-1]=names[i];
                                    names[i]=null;
                                    dishes[i-1]=dishes[i];
                                    times[i-1]=times[i];
                                    addresses[i-1]=addresses[i];
                                    totalAmount[i-1]=totalAmount[i];
                                    states[i-1]=states[i];
                                }
                                System.out.println("删除成功！");
                            }
                        System.out.print("输入0返回：");
                        num2 = input.nextInt();
                        break;
                    case 5:
                        System.out.println("************我要点赞**************");
                        System.out.println("\t\t\t序号\t\t名称\t\t单价\t\t点赞数");
                        System.out.println(" \t\t\t1\t\t红烧排骨\t30元\t\t"+count[0]);
                        System.out.println(" \t\t\t2\t\t季蔬\t\t10元\t\t"+count[1]);
                        System.out.println(" \t\t\t3\t\t肉末茄子\t15元\t\t"+count[2]);
                        System.out.println(" \t\t\t4\t\t红烧牛肉\t45元\t\t"+count[3]);
                        System.out.print("请选择点赞菜品编号：");
                        int num7=input.nextInt();//点赞菜品编号
                        boolean isGood=true;
                        switch (num7){
                            case 1:
                                count[0]++;
                                break;
                            case 2:
                                count[1]++;
                                break;
                            case 3:
                                count[2]++;
                                break;
                            case 4:
                                count[3]++;
                                break;
                            default:
                                System.out.println("点赞菜品不存在！");
                                isGood=false;
                                break;
                        }
                        if (isGood) {
                            System.out.println("点赞成功！");
                        }
                        System.out.print("输入0返回：");
                        num2 = input.nextInt();
                        break;
                    case 6:
                    default:
                        System.out.println("谢谢使用，欢迎再次光临!");
                        return;
                }
            } else {
                System.out.println("输入的数据不合法！");
            }
        }while(num2==0);

    }
}
